﻿using AppBox.BLL;
using System;
using System.Data;
using ZHDJ.Core;
using ZHDJ.Data.DataCaching;
using ZHDJ.Data.Models.Common;
using ZHDJ.WebPage;

namespace ZHDJ.Web
{
    public partial class ArticleDetailContent : PortalPage
    {
        #region 页面属性

        string DDicMemberName = string.Empty;

        public string ArticleID
        {
            get
            {
                return this.Request["id"];
            }
        }

        public string CategoryName
        {
            get
            {
                DataTable dt = null;
                PartyArticle article = DB.PartyArticles.Find(ArticleID);
                if (!string.IsNullOrEmpty(article.Category))
                {

                    dt = PartyArticle.GetCategory(article.Module, article.Category);
                    if (dt.Rows.Count > 0)
                    {
                        DDicMemberName = Convert.ToString(dt.Rows[0]["DDicMemberName"]);
                    }
                    return DDicMemberName;
                }
                else
                {
                    dt = PartyArticle.GetCategory("ZHDJ.Article.Module", article.Module);
                    if (dt.Rows.Count > 0)
                    {
                        DDicMemberName = Convert.ToString(dt.Rows[0]["DDicMemberName"]);
                    }
                    return DDicMemberName;
                }
            }
        }
        #endregion

        protected string webUrl = SystemParameterKey.WebHost;
        protected void Page_Load(object sender, EventArgs e)
        {
            PartyArticle article = DB.PartyArticles.Find(ArticleID);
            //标题支持换行
            this.lblTitle.Text = article.Title.Replace("\r\n", "<br />").Replace("\n", "<br />");
            this.lblTime.Text = "日期：" + Convert.ToDateTime(article.CreateTime).ToString("yyyy-MM-dd");
            this.lbBranch.Text = "发布：" + SystemParameterCaching.Get(SystemParameterKey.WebArticleHostName);

            this.ltContent.Text = article.Content;
            //客户要求隐藏文章图片
            //客户要求显示在底下，大点
            if (!string.IsNullOrEmpty(article.ImageID))
            {
                imgD.Visible = true;
                cImage.ImageUrl = UpFileBusiness.GetFileUrl(article.ImageID);
            }
            if (this.ArticleID == "joinpartyouth")
            {
                this.lblTitle.Visible = this.lblTime.Visible = this.lbBranch.Visible = false;
                this.divTitle.Visible = this.divLTime.Visible = false;
                cImage.Attributes.CssStyle.Value = "width:100%";
            }

            string sql = string.Format(@"SELECT file.Title,file.Url FROM tblpartyarticle as a
                                                INNER JOIN tblpartyarticlesfile as afile
                                                ON a.ID=afile.ArticleID
                                                LEFT JOIN tblpartyfile as file
                                                ON afile.FileID=file.ID
                                                WHERE a.ID='{0}';", article.ID);
            DataTable dt = ZHDJ.Data.MySqlHelper.ExecuteDataTable(sql);
            rpList.DataSource = dt;
            rpList.DataBind();

        }
    }
}